//
// Created by xujingyi on 2021/4/28.
//

#include <Setter.h>
#include "options.h"
#include "log.h"
#include <iostream>

rm::Setter::Setter(){
    cv::FileStorage SettingFile(PARAM_PATH,cv::FileStorage::READ);
    if (!SettingFile.isOpened()) {
        LOGE("[ERROR]:NO such Para.yaml file");
        return;
    }
//--------------------------------------run_param--------------------------------------#
    SettingFile["fixed_enemy_color"]>>fixed_enemy_color;
    //Calibration
    SettingFile["armor_camera_exposure"]>>armor_camera_exposure;
    SettingFile["sentry_height"]>>sentry_height;
//yaw 角度补偿系数:正数往右调
    SettingFile["yaw_angle_compensate"]>>yaw_angle_compensate;
//pitch 角度补偿系数：正数往下调
    SettingFile["pitch_angle_compensate"]>>pitch_angle_compensate;
//delay_time
    SettingFile["delay_time_compensate"]>>delay_time_compensate;
//distance
    SettingFile["pnp_distance_plus_coefficient"]>>pnp_distance_plus_coefficient;
    SettingFile["move_angle_plus_coefficient"]>>move_angle_plus_coefficient;
    SettingFile["anti_kalman_compensate_coefficient"]>>anti_kalman_compensate_coefficient;
    SettingFile["pitch_gravity_plus_coefficient"]>>pitch_gravity_plus_coefficient;
    SettingFile["highland_pitch_gravity_plus_coefficient"]>>highland_pitch_gravity_plus_coefficient;
    SettingFile["serial_yaw_angle_plus_coefficient"]>>serial_yaw_angle_plus_coefficient;
    SettingFile["serial_pitch_angle_plus_coefficient"]>>serial_pitch_angle_plus_coefficient;
    SettingFile["anti_switch_cnt_limit"]>>anti_switch_cnt_limit;
    SettingFile["keep_searching_for_same_box_limit"]>>keep_searching_for_same_box_limit;
    SettingFile["lost_then_keep_tracking_cnt_limit"]>>lost_then_keep_tracking_cnt_limit;
    SettingFile["tracking_time_cnt_limit"]>>tracking_time_cnt_limit;
    SettingFile["spinning_time_cnt_limit"]>>spinning_time_cnt_limit;
    SettingFile["not_shoot_chassis_speed"]>>not_shoot_chassis_speed;
    SettingFile["up_min_shoot_distance"]>>up_min_shoot_distance;
    SettingFile["up_max_shoot_distance"]>>up_max_shoot_distance;
    SettingFile["highland_blindview_min_distance"]>>up_min_shoot_distance;
    SettingFile["highland_blindview_max_distance"]>>up_min_shoot_distance;
    SettingFile["highland_height"]>>highland_height;
    SettingFile["cruise_judge_speed"]>>cruise_judge_speed;
    SettingFile["change_armor_angle"]>>change_armor_angle;
    SettingFile["switch2gyro_absdif_limit"]>>switch2gyro_absdif_limit;
    SettingFile["switch2gyro_velocity_limit"]>>switch2gyro_velocity_limit;

    SettingFile["red_brightness_threshold_val"]>>red_brightness_threshold_val;
    SettingFile["blue_brightness_threshold_val"]>>blue_brightness_threshold_val;
    SettingFile["red_color_channel_threshold_val"]>>red_color_channel_threshold_val;
    SettingFile["blue_color_channel_threshold_val"]>>blue_color_channel_threshold_val;
    SettingFile["red_color_diff_threshold_val"]>>red_color_diff_threshold_val;
    SettingFile["blue_color_diff_threshold_val"]>>blue_color_diff_threshold_val;
    SettingFile["marker_min_peri"]>>marker_min_peri;
    SettingFile["marker_max_peri"]>>marker_max_peri;
    SettingFile["marker_min_height_width_ratio"]>>marker_min_height_width_ratio;
    SettingFile["marker_max_height_width_ratio"]>>marker_max_height_width_ratio;
    SettingFile["marker_min_distance_height_ratio"]>>marker_min_distance_height_ratio;
    SettingFile["marker_middle_distance_height_ratio"]>>marker_middle_distance_height_ratio;
    SettingFile["marker_max_distance_height_ratio"]>>marker_max_distance_height_ratio;

    SettingFile["couple_max_angle_diff"]>>couple_max_angle_diff;
    SettingFile["couple_max_lengths_ratio"]>>couple_max_lengths_ratio;
    SettingFile["couple_min_marker_box_anglediff"]>>couple_min_marker_box_anglediff;

    SettingFile["perspect_num_box_plus_ratio"]>>perspect_num_box_plus_ratio;
    SettingFile["rect_num_box_plus_ratio"]>>rect_num_box_plus_ratio;
    SettingFile["tracking_box_plus_ratio"]>>tracking_box_plus_ratio;
    SettingFile["num_threshold"]>>num_threshold;
    SettingFile["num_img_size"]>>num_img_size;

    SettingFile["pass_score"]>>pass_score;
/*--------------------------------------camera_para--------------------------------------*/
    camera_matrix = cv::Mat(3,3,CV_32FC1);
    distcoeffs = cv::Mat(1,5,CV_32FC1);
    camera2ptz=(cv::Mat_<camera2ptz_Type >(1,3)<<SettingFile["camera2ptz"]);
//    camera2ptz=cv::Mat(1,3,CV_16FC1);
    SettingFile["camera2ptz"]>>camera2ptz;
    SettingFile["camera_matrix"]>>camera_matrix;
    SettingFile["distcoeffs"]>>distcoeffs;

/*--------------------------------------show_info--------------------------------------*/
    SettingFile["show_markers"]>>show_markers;
    SettingFile["show_marker_couples"]>>show_marker_couples;
    SettingFile["show_threshold_num"]>>show_threshold_num;
    SettingFile["show_armor"]>>show_armor;
    SettingFile["show_num_roi"]>>show_num_roi;
    SettingFile["show_warp_num"]>>show_warp_num;
    SettingFile["show_armors"]>>show_armors;
    SettingFile["show_origin"]>>show_origin;
    SettingFile["show_preprocess"]>>show_preprocess;
    SettingFile["show_predict_pos_graph"]>>show_predict_pos_graph;
    SettingFile["show_plot"]>>show_plot;
    SettingFile["show_CSYS"]>>show_CSYS;
    SettingFile["show_midline"]>>show_midline;
    SettingFile["show_track_box"]>>show_track_box;
    SettingFile["show_testboard"]>>show_testboard;
    SettingFile["wait_uart"]>>wait_uart;

    SettingFile["show_src_cnt"]>>show_src_cnt;
    SettingFile["run_by_frame"]>>run_by_frame;

    SettingFile["save_internal"]>>save_internal;
    SettingFile["save_num_picture"]>>save_num_picture;
    SettingFile["save_miss_picture"]>>save_miss_picture;
    SettingFile["save_wrong_picture"]>>save_wrong_picture;
    SettingFile["save_show_picture"]>>save_show_picture;

    SettingFile["print_state_switch_test_info"]>>print_state_switch_test_info;
}
